import moment from 'moment';
import qs from 'qs';

//json转url参数
export const parseParam = function(param, obj) {
  if (!obj || !param) {
    return param;
  }
  var paramurl = param;
  var keys = Object.keys(obj);
  if (keys.length != 0) {
    paramurl += '?' + qs.stringify(obj);
  }
  return paramurl;
};

//* 获取顶层对象
export var getGlobal = function() {
  if (typeof self !== 'undefined') {
    return self;
  }
  if (typeof window !== 'undefined') {
    return window;
  }
  if (typeof global !== 'undefined') {
    return global;
  }
  throw new Error('unable to locate global object');
};

//部署了一个误差检查函数。
export function withinErrorMargin(left, right) {
  return Math.abs(left - right) < Number.EPSILON * Math.pow(2, 2);
}
